import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:x_common_utils/utils/inkWell_util.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:get/get.dart';

class SearchBar extends StatelessWidget {

  final CommonPageController commonPageController;
  final ValueChanged<String> onChanged;
  final ValueChanged<String> onSubmitted;
  final String defaultValue;
  
  SearchBar({
    required this.commonPageController,
    required this.onChanged, 
    required this.onSubmitted,
    this.defaultValue = ''
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 54.h,
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      child: Row(
        children: [
          Expanded(child: Container(
            height: 36.h,
            padding: EdgeInsets.symmetric(horizontal: 10.w),
            decoration: BoxDecoration(
              color: pageBgColor,
              borderRadius: BorderRadius.circular(43.w)
            ),
            child: Row(
              children: [
                Image.asset(
                  'assets/icons/icon_search.png',
                  width: 18.w,
                  height: 18.w,
                ),
                SizedBox(width: 10.w),
                Expanded(child: TextField(
                  controller: TextEditingController(text: defaultValue),
                  textAlignVertical: TextAlignVertical.bottom,
                  decoration: InputDecoration(
                    isDense: true,
                    border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                    enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                    focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
                    counterText: '',
                    hintText: '关键词搜索',
                    hintStyle: TextStyle(
                      fontSize: 14.sp,
                      color: tipsColor,
                    )
                  ),
                  cursorColor: textBlackColor,
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: textBlackColor
                  ),
                  onChanged: (String value) => onChanged(value),
                  onSubmitted: (String value) => onSubmitted(value),
                ))
              ],
            ),
          )),
          SizedBox(width: 12.w),
          InkWellUtil.shakeProofInkWell(Image.asset(
            'assets/icons/icon_notice_b.png',
            width: 20.w,
            height: 20.w,
          ), () {
            Get.back();
            if (commonPageController.isRevirew.value) {
              commonPageController.tabIndex.value = 1;
            } else {
              commonPageController.tabIndex.value = 2;
            }
          })
        ],
      ),
    );
  }
}